package com.cherry.web.controller.system;

import com.cherry.common.core.controller.BaseController;
import com.cherry.common.core.domain.AjaxResult;
import com.cherry.common.core.domain.entity.SysUser;
import com.cherry.common.utils.StringUtils;
import com.cherry.framework.shiro.service.SysRegisterService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;

/**
 * 用户注册 控制层
 *
 * @author 孙晨阳
 */
@Controller
public class SysRegisterController extends BaseController {

    @Resource
    private SysRegisterService registerService;

    /**
     * 访问/register时跳转至用户注册页面
     *
     * @return 跳转的页面
     */
    @GetMapping("/register")
    public String register() {
        return "register";
    }

    /**
     * ajax方式发起注册请求
     *
     * @param user 要注册的用户信息
     * @return json结果
     */
    @PostMapping("/register")
    @ResponseBody
    public AjaxResult ajaxRegister(SysUser user) {
        String msg = registerService.register(user);
        return StringUtils.isEmpty(msg) ? success() : error(msg);
    }

}
